<template>
	<view class="uni-common-mt">

		<view class="title">
			<image @click="back()" src="../../static/fanhui.png"
				style="float: left; width: 20px;vertical-align: middle;height: 20px;" mode=""></image> 归还车辆

		</view>
		<view class="content">
			<view class="carimg">
				<image :src="imageUrl" mode=""></image>
			</view>
			<view class="label">
				用户名
			</view>

			<view class="uni-form-item uni-column">
				<input type="text" class="uni-input" disabled v-model="form.username">
			</view>
			<view class="label">
				真实姓名
			</view>

			<view class="uni-form-item uni-column">
				<input type="text" class="uni-input" v-model="form.name" disabled>
			</view>
			<view class="label">
				电话
			</view>

			<view class="uni-form-item uni-column">
				<input type="text" class="uni-input" v-model="form.phone" disabled>
			</view>

			<view class="label">
				身份证
			</view>

			<view class="uni-form-item uni-column">
				<input type="text" class="uni-input" v-model="form.sfz" disabled placeholder="请输入身份证">
			</view>
			<view class="label">
				租赁时间
			</view>
			<view class="">
				<el-date-picker type="date" style="width:100%" disabled value-format="yyyy-MM-dd"
					v-model="form.zlsj"></el-date-picker>
			</view>
			<view class="label">
				归还时间
			</view>
			<view class="uni-form-item uni-column">
				<el-date-picker type="date" value-format="yyyy-MM-dd" disabled style="width:100%"
					v-model="form.ghsj"></el-date-picker>
			</view>
			<view class="label">
				总价
			</view>
			<view class="uni-form-item uni-column">
				<input style="width:100%" v-model="form.price" disabled class="uni-input"></input>
			</view>
			<view class="tip">
				*注意:需要到现场付费后才能租赁
			</view>

			<view class="submit">
				<!-- 	<button @click="submit()">计算总价</button> -->
				<button @click="submit1()" v-if="form.status ==1">归还</button>
								<button @click="back()" v-else>返回</button>
			</view>


		</view>


	</view>
</template>
<style>
	.carimg image {
		width: 100%;

	}

	.carimg {
		width: 100%;

	}

	.tip {
		color: red;
		font-size: 13px;
	}
</style>
<script>
	export default {
		data() {
			return {
				carid: "",
				form: {},
				imageUrl: "",
				zj: "",
				headers: {
					token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IjQ1NioqKkBxcS5jb20iLCJwaG9uZSI6IjEzNyoqKio1NDQ5IiwiaWQiOjEsInVzZXJuYW1lIjoiY2VzaGkxIiwibmlja25hbWUiOiIiLCJwYXNzd29yZCI6IjA5MTNmYWIyOWY4YWE5MmY5N2ZlNjQ2ODM5NDA5ZjM3MjZjNGQzZGM2NGY0NDlmMTA2MjJhNTUwMGM3NDBjMDIiLCJhdmF0YXIiOiIiLCJ3ZWl4aW5fdW5pb25pZCI6bnVsbCwic2V4Ijoi5pyq55-lIiwiZGVzYyI6IiIsInN0YXR1cyI6MSwiY3JlYXRlZF90aW1lIjoiMjAyMS0wMi0yMVQxNDowNDowMi4wMDBaIiwidXBkYXRlZF90aW1lIjoiMjAyMy0xMC0wNFQxNjo0ODo0MC4wMDBaIiwiaWF0IjoxNjk4NTYyOTU4fQ.MLAxkr9JkR9lIxEZbufSuBDB_kz-GR8UYEvwB3NslcA",
					schoolid: "11"

				},
			}
		},

		mounted() {
			// this.form = JSON.parse(window.localStorage.getItem("userinfo"));
			// this.form.uid=this.form.id
			// delete this.form.id
			// console.log(this.form)
		},
		onLoad(e) {
			console.log(e.data)
			this.form = JSON.parse(e.data);
			// this.carid=e.id;
			this.imageUrl = this.form.carimg

			// this.zj=e.zj
		},
		methods: {
			back() {
				uni.navigateTo({
					url: "/pages/mygh/mygh"
				});
			},

			isEmail(email) {
				let emailRegExp = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
				var result = emailRegExp.test(email)
				if (!result) {
					uni.showToast({
						icon: "none",
						title: "邮箱格式不正确"
					})
					return false
				} else {
					return true
				}

			},

			checkmobile(mobile) {
				var re = /^1[3,4,5,6,7,8,9][0-9]{9}$/;
				var result = re.test(mobile);
				if (!result) {
					uni.showToast({
						icon: "none",
						title: "手机号格式不正确"
					})
					return false
				} else {
					return true
				}
			},
			submit() {
				if (this.form.zlsj > this.form.ghsj) {
					uni.showToast({
						icon: "none",
						title: "归还时间不能小于租赁时间"
					})
				}
				let day1 = Date.parse(this.form.ghsj)
				let day2 = Date.parse(this.form.zlsj);
				let day = this.form.ghsj - this.form.zlsj;
				let diffdate = Math.abs(day1 - day2)
				let totalday = Math.floor(diffdate / (1000 * 3600 * 24))
				console.log(totalday)
				this.form.price = totalday * Number(this.zj)
				console.log(this.form.price)
				this.$forceUpdate()
			},
			submit1() {
				// this.form.carid = this.carid
				this.form.status = 3
				uni.request({
					url: "index/gh",
					method: "POST",
					data: this.form,
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {
							uni.showToast({
								title: "提交成功",
								icon: "none"
							})
							uni.navigateTo({
								url: "/pages/myzl/myzl"
							})
						}
					}
				})
			},
			handleAvatarSuccess(e) {
				console.log(e)
				this.form.avator = e.data
			},
			sctx() {
				uni.chooseImage({
					success(res) {
						console.log(res)
						uni.request({
							url: "admin/s/upload",
							method: "POST",
							headers: {
								token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IjQ1NioqKkBxcS5jb20iLCJwaG9uZSI6IjEzNyoqKio1NDQ5IiwiaWQiOjEsInVzZXJuYW1lIjoiY2VzaGkxIiwibmlja25hbWUiOiIiLCJwYXNzd29yZCI6IjA5MTNmYWIyOWY4YWE5MmY5N2ZlNjQ2ODM5NDA5ZjM3MjZjNGQzZGM2NGY0NDlmMTA2MjJhNTUwMGM3NDBjMDIiLCJhdmF0YXIiOiIiLCJ3ZWl4aW5fdW5pb25pZCI6bnVsbCwic2V4Ijoi5pyq55-lIiwiZGVzYyI6IiIsInN0YXR1cyI6MSwiY3JlYXRlZF90aW1lIjoiMjAyMS0wMi0yMVQxNDowNDowMi4wMDBaIiwidXBkYXRlZF90aW1lIjoiMjAyMy0xMC0wNFQxNjo0ODo0MC4wMDBaIiwiaWF0IjoxNjk4NTYyOTU4fQ.MLAxkr9JkR9lIxEZbufSuBDB_kz-GR8UYEvwB3NslcA",
								schoolid: "11"

							},
							data: {
								// file:res.tempFilePaths[0]
								// file: `‪C:\Users\NINGMEI\Pictures\1.jpeg`
							},
							success: (res1) => {
								console.log(res1)
							}


						})

					}
				})
			}

		}
	}
</script>
<style>
	.el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
</style>
<style scoped>
	.uni-common-mt {
		width: 100%;
		height: 100%;
		background: #e5e5e5;

	}

	.uni-form-item {
		margin-top: 10px;
		margin-bottom: 10px;

	}

	.content {
		height: calc(100% - 39px);
		overflow: auto;
		padding: 10px;
		box-sizing: border-box;
	}

	.label {
		font-size: 14px;

	}

	.uni-input {
		background: #fff;
		height: 30px;
		line-height: 30px;
		padding: 0px 10px;
		box-sizing: border-box;
		border-radius: 2px;
	}

	.title {
		width: 100%;
		height: auto;
		padding: 10px;
		box-sizing: border-box;
		background: purple;
		color: #fff;
		text-align: center;
		font-size: 14px;
	}
</style>